<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <!-- 引入自己的样式 -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/style/css/login.css">

    <!-- Custom styles for this template -->
<%--    <link href="${pageContext.request.contextPath}/style/css/signin.css" rel="stylesheet">--%>

    <script src="${pageContext.request.contextPath}/style/js/jquery-3.5.1.js"></script>

    <!-- 引入favicon图标 -->
    <link rel="shortcut icon" href="../ficon.ico">

</head>

<body>
<div class="login_tit">
    <p class="login_tit1">高校就业大数据管理系统</p>
    <p class="login_tit2"> ------身 份 认 证</p>
</div>

    <form id="frm" class="form-signin login"  method="post" style="height: 379px">
        <p>账号登录</p>
        <div class="auth_content">

            <p class="auth_icon">
<%--                <label for="name" class="sr-only">用户名</label>--%>
                <input type="text"  id="name" class="form-control" placeholder="用户名" name="name"></br>
            </p>
            <p class="auth_icon">
<%--                <label for="pwd" class="sr-only">密码</label>--%>
                <input type="password" id="pwd" class="form-control" placeholder="密码" name="pwd"></br>
            </p>
            <p class="auth_icon">
<%--                <label for="pwd2" class="sr-only">确认密码</label>--%>
                <input type="password"  id="pwd2" class="form-control" placeholder="确认密码" name="pwd2"></br>
            </p>
            <p class="auth_icon">
<%--                <label for="phone" class="sr-only">手机号</label>--%>
                <input type="text" id="phone"  class="form-control" placeholder="手机号" name="phone"></br>
            </p>
            <button class="btn btn-lg btn-primary btn-block" type="button" onclick="doRegister()" style="width: 30%">添加</button>

        </div>

     </form>



</div>
</body>
</html>

<script>




<%--    注册验证--%>
    function doRegister() {
        //推荐前端js验证字段
        var myreg =/^(13[0-9]|14[5-9]|15[0-35-9]|16[25-7]|17[0-8]|18[0-9]|19[0135689])[0-9]{8}$/;
        var reg=/^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])/;
        var pwd=$("#pwd").val();
        var pwd2=$("#pwd2").val();
        var phone=$("#phone").val();
        if(phone == '' || phone == undefined || phone == null || pwd == '' || pwd == undefined || pwd == null|| pwd2 == '' || pwd2 == undefined || pwd2 == null){
            alert('账号或者密码不能为空');
        }else if (pwd!=pwd2){
            alert("两次密码不一致");
        }
        else if(phone.length !=11){
            alert('请输入有效的手机号码！');
        }else if(!myreg.test(phone)){
            alert('请输入有效的手机号码！');
        }else if(pwd.length<8){alert('密码长度不能小于八位');
        }
        else if(!reg.test(pwd)){alert('请输入含有大小写字母数字的密码');
        }
         else{
            $.ajax(
                {
                    type:"post",
                    url:"/admin/doRegister",
                    data:$("#frm").serialize(),
                    async:false,  //使用ajax同步提交数据
                    success:function (response) {
                        if (response=="exist"){
                            alert("注册失败，用户名已经存在");
                        }else  if (response=="OK"){
                            alert("注册成功一秒后跳转登录页面");
                            setTimeout(window.location.href='/jsp/admin/login.jsp',1000);
                        }else{
                            alert("添加失败，请联系管理员....");
                        }
                    }
                }
            );
        }
    }
</script>